import React, { PureComponent } from "react";
import { connect } from "dva";
import Link from 'umi/link';
import moment from "moment";
import { Card, Table, Badge } from "antd";
import styles from "./component.less";




@connect(({ monitor,global, loading }) => ({
  dictionaries:global.dictionaries,
  TableData:monitor.maintenancTrack,
  loading: monitor.loading.maintenancTrack,
}))
export default class Dashboard extends PureComponent {
  constructor(props) {
    super(props);

  }

  componentDidMount() {
    this.getData();
    this.timerID = setInterval(
      () => this.getData(),
      1000*60*2
    );

  }

  componentWillUnmount() {
    clearInterval(this.timerID);
  }


  getData =() =>{
    const { dispatch } = this.props;
    dispatch({
      type: 'monitor/fetch_mainten_track',
    });
  }



  render() {
    const { TableData, loading, dictionaries } = this.props;


    const taskStatus = dictionaries.taskStatus && dictionaries.taskStatus.length>1
      ? dictionaries.taskStatus.map(item=>item.label)
      :[];

    const columns = [{
      title: '名称',
      dataIndex: 'devName',
      render: text=> <span>{text}</span>
    },{
      title: '编号',
      dataIndex: 'devCode',
      render: text=> <span>{text}</span>
    },{
      title: '执行人',
      dataIndex: 'signPerson',
      render: text=> <span>{text}</span>
    },{
      title: '到达时间',
      dataIndex: 'signTime',
      render: text=> <span>{moment(text).format("YYYY-MM-DD HH:mm")}</span>
    },{
      title: '安装点位',
      dataIndex: 'pointName',
      render: text=> <span>{text}</span>
    },{
      title: '反馈',
      dataIndex: 'status',
      render: (text,row)=><span>{taskStatus[parseInt(text)-1]}</span>,
    }];





    return (
      <Card
        title={ <span><Badge status="processing" />养护跟踪</span>}
        bordered={false}
        bodyStyle={{padding:0}}
        hoverable={true}
        style={{marginTop:0,position:'absolute',bottom:0,width:'100%',height:230}}
        className={styles.tablechart_card}
      >
        <Table className={styles.tablechartnormal}
               columns={columns}
               dataSource={TableData}
               pagination={false}
               size="small"
               rowKey={"devId"}
               loading={loading}

        />
      </Card>
    );
  }
}
